package com.marvels.approve.process.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.druid.util.StringUtils;
import com.marvels.approve.credit.dto.McamAttachmentInfoDTO;
import com.marvels.approve.credit.service.CreditReportService;
import com.marvels.approve.process.dto.ScreenshotsDTO;
import com.marvels.approve.process.service.CreditDataService;
import com.marvels.common.dto.MarvelsApiResultDTO;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

@RequestMapping("/approve/credit/report/api")
@RestController
public class RefusedDateController {
	@Autowired
	CreditReportService creditReportService;
	/**
	 * 获取保单存储路径数据入库
	 * @param params
	 * @return
	 */
	@RequestMapping("screenshotsData")
	@ResponseBody
	public MarvelsResultDTO submitDate(@RequestBody ScreenshotsDTO screenshotsDTO){
		try {
			Integer count = null;
			count = creditReportService.savaScreenshotsData(screenshotsDTO);				
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), count);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	/**
	 * 签名附件覆盖原签名影像文件
	 * @param screenshotsDTO
	 * @return
	 */
	@RequestMapping("updateImageInfo")
	@ResponseBody
	public MarvelsResultDTO updateImageInfo(@RequestBody ScreenshotsDTO screenshotsDTO){
		try {
			Integer count = null;
			count = creditReportService.updateImageInfo(screenshotsDTO);				
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), count);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**
	 * 查看合同
	 * @param screenshotsDTO
	 * @return
	 */
	@RequestMapping("queryContract")
	@ResponseBody
	public MarvelsResultDTO queryContract(@RequestBody ScreenshotsDTO screenshotsDTO){
		try {
			List<McamAttachmentInfoDTO> queryContract = creditReportService.queryContract(screenshotsDTO.getLoanId());
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), queryContract);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}

}
